#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
#define MAX_N 50005
struct node
{
    char key[500];
    int priority;
    int lch,rch,par;
    node()
    {
        lch = rch = par = -1;
    }
} treap[MAX_N];

int n;

struct cmp
{
    bool operator()(const node &a , const node &b)
    {
        return (strcmp(a.key,b.key)<0);
    }
};

void Insert(int cur)
{
    int j  = cur-1;
    while (treap[j].priority < treap[cur].priority )j = treap[j].par;
    treap[cur].lch = treap[j].rch;
    treap[j].rch = cur;
    treap[cur].par = j;

}

void dfs(int cur)
{
    if (cur==-1) return ;
    printf("(");
    dfs(treap[cur].lch);
    printf("%s/%d",treap[cur].key,treap[cur].priority);
    dfs(treap[cur].rch);
    printf(")");
}

int main()
{
   // freopen("1785.txt","r",stdin);


    while (scanf("%d",&n)!=EOF && n)
    {

        for (int i = 1; i <= n ; i++)
        {
            scanf("%*[ ]%[a-z]/%d",treap[i].key,&treap[i].priority);
            treap[i].lch = treap[i].rch = treap[i].par = -1;
        }
        sort(treap+1,treap+n+1,cmp());

        treap[0].priority = 0x7fffffff;
        treap[0].lch = treap[0].rch = treap[0].par = -1;
        for (int i = 1 ; i <=  n ; i++) Insert(i);
        /*for (int i = 1 ; i <= n ; i++)
        {
            cout<<"#"<<i<<" " << treap[i].key<<"/"<<treap[i].priority<<" " <<treap[i].lch << " "<<treap[i].rch<<endl;
        }*/
        dfs(treap[0].rch);
        printf("\n");
    }
    return 0;
}
